package guzb.cnblogs.security.industrydemo.controller;

import guzb.cnblogs.security.industrydemo.util.JsonResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Properties;

/**
 * 本 Controller 用于模拟前端分离的架构场景
 */
@RestController
@RequestMapping(path="/api/app")
public class RestfulController {

    @GetMapping(path="/books")
    public JsonResponse<String[]> listBooks() {
        String[] books = new String[] {
                "出埃及记",
                "明朝哪些事",
                "盐亭县志",
                "已亥杂诗",
                "纪念终将逝去的青春"
        };
        return JsonResponse.ok(books);
    }

    @GetMapping(path="/system")
    public JsonResponse<SystemInfo> getSystemInfo() {
        SystemInfo systemInfo = new SystemInfo();
        systemInfo.setDescription("Content of this page are secret, thus,\n" +
                " It permit super user that has advance privilege,\n" +
                " for example the user with role of Amin, to access only for security reason");

        systemInfo.addProperty("System", "Windows 11 Pro");
        systemInfo.addProperty("Version", "21H2");
        systemInfo.addProperty("Experience", "Windows Feature Experience Pack 1000.22000.1335.0");
        systemInfo.addProperty("System Type", "64-bit operating system, x64-based processor");
        systemInfo.addProperty("Processor", "Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz 2.50 GHz");

        return JsonResponse.ok(systemInfo);
    }

    static class SystemInfo {
        private String description;

        private Properties properties = new Properties();

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public Properties getProperties() {
            return properties;
        }

        void addProperty(String name, String value) {
            this.properties.setProperty(name, value);
        }
    }
}
